home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / hity wydania / Ubuntu 9.10 PL / karmelkowy-koliberek-desktop-9.10-i386-PL.iso / casper / filesystem.squashfs / usr / lib / python2.6 / dist-packages / debconf.pyc (.txt) < prev    next >
Python Compiled Bytecode  |  2009-10-28  |  6KB  |  195 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. import sys
  5. import os
  6. import errno
  7. import re
  8.  
  9. try:
  10.     import subprocess
  11.     using_subprocess = True
  12. except ImportError:
  13.     import popen2
  14.     using_subprocess = False
  15.  
  16. import fcntl
  17.  
  18. class DebconfError(Exception):
  19.     pass
  20.  
  21. (LOW, MEDIUM, HIGH, CRITICAL) = ('low', 'medium', 'high', 'critical')
  22.  
  23. class Debconf:
  24.     
  25.     def __init__(self, title = None, read = None, write = None):
  26.         for command in 'capb set reset title input beginblock endblock go get register unregister subst fset fget previous_module visible purge metaget exist version settitle info progress data'.split():
  27.             self.setCommand(command)
  28.         
  29.         if not read:
  30.             pass
  31.         self.read = sys.stdin
  32.         if not write:
  33.             pass
  34.         self.write = sys.stdout
  35.         sys.stdout = sys.stderr
  36.         self.setUp(title)
  37.  
  38.     
  39.     def setUp(self, title):
  40.         self.version = self.version(2)
  41.         if self.version[:2] != '2.':
  42.             raise DebconfError(256, 'wrong version: %s' % self.version)
  43.         self.version[:2] != '2.'
  44.         self.capabilities = self.capb().split()
  45.         if title:
  46.             self.title(title)
  47.         
  48.  
  49.     
  50.     def setCommand(self, command):
  51.         None(setattr, (self, command), (lambda : self.command(command, *args, **kw)))
  52.  
  53.     
  54.     def command(self, command, *params):
  55.         command = command.upper()
  56.         self.write.write('%s %s\n' % (command, ' '.join(map(str, params))))
  57.         self.write.flush()
  58.         while True:
  59.             
  60.             try:
  61.                 resp = self.read.readline().rstrip('\n')
  62.             continue
  63.             except IOError:
  64.                 e = None
  65.                 if e.errno == errno.EINTR:
  66.                     continue
  67.                 else:
  68.                     raise 
  69.                 e.errno == errno.EINTR
  70.             
  71.  
  72.             None<EXCEPTION MATCH>IOError
  73.         if ' ' in resp:
  74.             (status, data) = resp.split(' ', 1)
  75.         else:
  76.             status = resp
  77.             data = ''
  78.         status = int(status)
  79.         if status == 0:
  80.             return data
  81.         if status == 1:
  82.             unescaped = ''
  83.             for chunk in re.split('(\\\\.)', data):
  84.                 if chunk.startswith('\\') and len(chunk) == 2:
  85.                     if chunk[1] == 'n':
  86.                         unescaped += '\n'
  87.                     else:
  88.                         unescaped += chunk[1]
  89.                 chunk[1] == 'n'
  90.                 unescaped += chunk
  91.             
  92.             return unescaped
  93.         raise DebconfError(status, data)
  94.  
  95.     
  96.     def stop(self):
  97.         self.write.write('STOP\n')
  98.         self.write.flush()
  99.  
  100.     
  101.     def forceInput(self, priority, question):
  102.         
  103.         try:
  104.             self.input(priority, question)
  105.             return 1
  106.         except DebconfError:
  107.             e = None
  108.             if e.args[0] != 30:
  109.                 raise 
  110.             e.args[0] != 30
  111.  
  112.         return 0
  113.  
  114.     
  115.     def getBoolean(self, question):
  116.         result = self.get(question)
  117.         return result == 'true'
  118.  
  119.     
  120.     def getString(self, question):
  121.         return self.get(question)
  122.  
  123.  
  124.  
  125. class DebconfCommunicator(Debconf, object):
  126.     
  127.     def __init__(self, owner, title = None, cloexec = False):
  128.         args = [
  129.             'debconf-communicate',
  130.             '-fnoninteractive',
  131.             owner]
  132.         if using_subprocess:
  133.             self.dccomm = subprocess.Popen(args, stdin = subprocess.PIPE, stdout = subprocess.PIPE, close_fds = True)
  134.             read = self.dccomm.stdout
  135.             write = self.dccomm.stdin
  136.         else:
  137.             self.dccomm = popen2.Popen3(args)
  138.             read = self.dccomm.fromchild
  139.             write = self.dccomm.tochild
  140.         super(DebconfCommunicator, self).__init__(title = title, read = read, write = write)
  141.         if cloexec:
  142.             fcntl.fcntl(self.read.fileno(), fcntl.F_SETFD, fcntl.FD_CLOEXEC)
  143.             fcntl.fcntl(self.write.fileno(), fcntl.F_SETFD, fcntl.FD_CLOEXEC)
  144.         
  145.  
  146.     
  147.     def shutdown(self):
  148.         if self.dccomm is not None:
  149.             if using_subprocess:
  150.                 self.dccomm.stdin.close()
  151.                 self.dccomm.stdout.close()
  152.             else:
  153.                 self.dccomm.tochild.close()
  154.                 self.dccomm.fromchild.close()
  155.             self.dccomm.wait()
  156.             self.dccomm = None
  157.         
  158.  
  159.     
  160.     def __del__(self):
  161.         
  162.         try:
  163.             self.shutdown()
  164.         except AttributeError:
  165.             pass
  166.  
  167.  
  168.  
  169. if 'DEBCONF_USE_CDEBCONF' in os.environ and os.environ['DEBCONF_USE_CDEBCONF'] != '':
  170.     _frontEndProgram = '/usr/lib/cdebconf/debconf'
  171. else:
  172.     _frontEndProgram = '/usr/share/debconf/frontend'
  173.  
  174. def runFrontEnd():
  175.     if 'DEBIAN_HAS_FRONTEND' not in os.environ:
  176.         os.environ['PERL_DL_NONLAZY'] = '1'
  177.         os.execv(_frontEndProgram, [
  178.             _frontEndProgram,
  179.             sys.executable] + sys.argv)
  180.     
  181.  
  182. if __name__ == '__main__':
  183.     runFrontEnd()
  184.     db = Debconf()
  185.     db.forceInput(CRITICAL, 'bsdmainutils/calendar_lib_is_not_empty')
  186.     db.go()
  187.     less = db.getBoolean('less/add_mime_handler')
  188.     aptlc = db.getString('apt-listchanges/email-address')
  189.     db.stop()
  190.     print db.version
  191.     print db.capabilities
  192.     print less
  193.     print aptlc
  194.  
  195.